package com.zznode.redsun.smartcrm.console.action;

import java.util.Collection;

import org.apache.shiro.SecurityUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.zznode.redsun.commons.sercurity.mapper.SecurityMapper;
import com.zznode.redsun.commons.sercurity.model.Permission;
import com.zznode.redsun.commons.sercurity.shiro.LoginUser;
import com.zznode.redsun.commons.utils.AbstractBaseAction;

@Controller
@Namespace("/console")
public class ConsoleAction extends AbstractBaseAction {
	private static final long serialVersionUID = 1L;
	private static final Logger logger = LoggerFactory.getLogger(ConsoleAction.class);

	@Autowired
	private SecurityMapper securityMapper;

	@Action(value = "index", results = { @Result(name = SUCCESS, location = "index.jsp") })
	public String index() {
		logger.info("===>>access in this.");
		return SUCCESS;
	}

	@Action(value = "top", results = { @Result(name = SUCCESS, location = "top.jsp") })
	public String top() {
		return SUCCESS;
	}

	@Action(value = "left", results = { @Result(name = SUCCESS, location = "left.jsp") })
	public String left() {
		@SuppressWarnings("unchecked")
		LoginUser<String> principal = (LoginUser<String>) SecurityUtils.getSubject().getPrincipal();
		Collection<Permission> permissions = securityMapper.findPermissions(principal.getLoginName());
		this.putValueStack("permissions", permissions);
		return SUCCESS;
	}

	@Action(value = "main", results = { @Result(name = SUCCESS, location = "main.jsp") })
	public String main() {
		return SUCCESS;
	}
}
